<?php

/**
 * Class UserNewMsg
 */
class UserNewMsg
{
    /** @var int */
    protected $id = 0;
    /** @var int */
    protected $userId = 0;
    /** @var int */
    protected $new_msg_count = 0;
    /** @var string */
    protected $new_msg_id_json = '[]';

    /**
     * @return int
     */
    public function msgCountPlusOne()
    {
        $this->new_msg_count++;
        return $this->new_msg_count;
    }

    /**
     * @param int $commentId
     * @return int
     */
    public function addCommentId($commentId)
    {
        $new_msg_id_array = json_decode($this->getNewMsgIdJson(), true);
        if (!isset($new_msg_id_array['comment_ids'])) {
            $new_msg_id_array['comment_ids'] = array();
        }
        if (in_array($commentId, $new_msg_id_array['comment_ids'])) {
            return $new_msg_id_array;
        };
        $new_msg_id_array['comment_ids'][] = $commentId;
        $this->setNewMsgIdJson(json_encode($new_msg_id_array));
        $this->msgCountPlusOne();
        return $new_msg_id_array;
    }

    /**
     * @param int $commentRequireId
     * @return int
     */
    public function addCommentRequireId($commentRequireId)
    {
        $new_msg_id_array = json_decode($this->getNewMsgIdJson(), true);
        if (!isset($new_msg_id_array['comment_require_ids'])) {
            $new_msg_id_array['comment_require_ids'] = array();
        }
        if (in_array($commentRequireId, $new_msg_id_array['comment_require_ids'])) {
            return $new_msg_id_array;
        };
        $new_msg_id_array['comment_require_ids'][] = $commentRequireId;
        $this->setNewMsgIdJson(json_encode($new_msg_id_array));
        $this->msgCountPlusOne();
        return $new_msg_id_array;
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param int $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @return int
     */
    public function getUserId()
    {
        return $this->userId;
    }

    /**
     * @param int $userId
     */
    public function setUserId($userId)
    {
        $this->userId = $userId;
    }

    /**
     * @return int
     */
    public function getNewMsgCount()
    {
        return $this->new_msg_count;
    }

    /**
     * @param int $new_msg_count
     */
    public function setNewMsgCount($new_msg_count)
    {
        $this->new_msg_count = $new_msg_count;
    }

    /**
     * @return string
     */
    public function getNewMsgIdJson()
    {
        return $this->new_msg_id_json;
    }

    /**
     * @param string $new_msg_id_json
     */
    public function setNewMsgIdJson($new_msg_id_json)
    {
        $this->new_msg_id_json = $new_msg_id_json;
    }

}